# start_ui.py
import os, sys, time
from sweetest.autotest import Autotest
from sweetest.globals import g
from sweetest.keywords.windows import WindowsDriverProxy
import te_11

# te_11.kill_max_processes()
# te_11.release_max_ports()

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
LAUNCHER_PATH = r"E:\Tjf\Max-Optics\3330\v3.3.3.0_09250451\gui\launcher\MaxOpticsLauncher.exe"
# LAUNCHER_PATH = r"C:\Users\tanjingfei\Desktop\12345.mop"

# 1) 初始化计划
plan_name = "ManGuang_ui_test"
sheet_name = "调试1"
desired_caps = {"platformName": "windows", "browserName": "chromium", "headless": False}
server_url = ""

# 2) 初始化框架（内部会 g.init()）
sweet = Autotest(plan_name, sheet_name, desired_caps, server_url)

# 3) 显式创建 driver，并代码侧启动 Electron
g.driver = WindowsDriverProxy(worker_path=os.path.join(BASE_DIR, "playwright_worker.js"))
g.driver.launch_app(name="launcher", path=LAUNCHER_PATH, args=[], wait_ms=5000)

# 4) 把控制权交给 Excel（第一步直接是 WAIT_FOR/CLICK 等）

try:
    sweet.plan()
except:
    pass
# te_11.kill_max_processes()
# te_11.release_max_ports()


